package com.wh1200.mybatis.xmlless.config

import com.wh1200.xmlless.test.dao.StudentDAO
import com.wh1200.xmlless.test.model.Student
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableName
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper
import jakarta.persistence.Column
import jakarta.persistence.Id
import jakarta.persistence.Table
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

/**
 *
 * @author 吴昊
 * @date 2023/12/19 14:49
 * @since v4.0.0
 * @version 1.0
 */

class TableInfoResolveTest : BaseResolverTest(
    StudentDAO::class.java
) {

  @Test
  fun test() {
    val a = TableInfoHelper.initTableInfo(builderAssistant, A::class.java)
    val b = TableInfoHelper.initTableInfo(builderAssistant, B::class.java)
    val c = TableInfoHelper.initTableInfo(builderAssistant, C::class.java)
    val d = TableInfoHelper.initTableInfo(builderAssistant, D::class.java)
    assertEquals("a_table", a.tableName)
    assertEquals("b_table", b.tableName)
    assertEquals("c_table", c.tableName)
    assertEquals("d", d.tableName)
    a.fieldList.forEach {
      println(it.property + "/" + it.column)
    }
    assertEquals("n1", a.fieldList.first { it.property == "name1" }.column)
    assertEquals("n2", a.fieldList.first { it.property == "name2" }.column)
    assertEquals("n3", a.fieldList.first { it.property == "name3" }.column)
    assertEquals("name4", a.fieldList.first { it.property == "name4" }.column)
    assertEquals("uid", a.keyProperty)
    assertEquals("a_id", a.keyColumn)
  }
}

@TableName("a_table")
class A {

  @Id
  @Column(name = "a_id")
  var uid: String? = null

  @TableField("n1")
  var name1: String? = null

  @Column(name = "n2")
  var name2: String? = null

  @TableField("n3")
  @Column(name = "n3")
  var name3: String? = null
  var name4: String? = null
}

@Table(name = "b_table")
class B

@TableName("c_table")
@Table(name = "cc_table")
class C


class D
